<template>
<div id="background">
    <el-container>
        <el-header id="addressHeadPosition">
                  <el-row type="flex" style="height:80%;display:flex;align-items: flex-end">
                    <el-col :xs="2" :sm="2" :md="2" :offset="1" class="imgCol">
                        <img v-bind:src="backIcon" class="backSize" @click="back"/>
                    </el-col>
                    <el-col :xs="6" :sm="6" :md="6" :offset="6" class="imgCol">
                        <span class="titleSize">收货地址</span>
                    </el-col>
                    <el-col :xs="3" :sm="3" :md="3" :offset="5" class="imgCol">
                        <span class="titleSize" @click="manageAddress">{{btnManage}}</span>
                    </el-col>
                </el-row>
        </el-header>
        <el-main id="addressScroll">
            <el-scrollbar  height="100%" style="margin-top:3%">
                <div v-for="info in infos" v-bind:key="info.id"  class="boxColor">
                    <div @click="goToEditAddress(info)">
                        <el-container style="padding:5px;height:80px"  >
                            <el-main >
                                <el-row type="flex" justify="space-around" style="margin-bottom:5px">
                                    <el-col :xs="16" :sm="16" :md="16"  style="margin-left:3%">
                                        <span class="addressWords">{{info.name}}</span>
                                    </el-col>
                                    <el-col :xs="8" :sm="8" :md="8" >
                                        <span class="addressWords">{{info.phone}}</span>
                                    </el-col>
                                </el-row>
                                <div style="margin-left:3%">
                                    <span class="addressWords" style="font-size:14px">{{info.province}}{{info.city}}{{info.area}}{{info.address}}</span>
                                </div>
                            </el-main>
                        </el-container>
                    </div>
                    <el-container v-show="editShow">
                        <el-main>
                            <el-row class="imgCol">
                                <div class="editLine"></div>
                            </el-row>
                            <el-row type="flex" style="margin-top:5px;margin-bottom:5px">
                                <!--<el-col :xs="2" :sm="2" :md="2" :offset="1" >
                                     <el-checkbox v-model="info.moRenAddress" ><span style="font-size:10px">设为默认</span></el-checkbox>
                                </el-col>-->
                                <el-col  :xs="4" :sm="4" :md="4" :offset="15">
                                    <i class="el-icon-edit-outline" style="color:#707070"  @click="goToEditAddress(info)"></i>
                                    <span style="font-size:10px;color:#707070"  @click="goToEditAddress(info)">编辑</span>
                                </el-col>
                                <el-col :xs="4" :sm="4" :md="4" :offset="1">
                                    <i class="el-icon-delete" style="color:#707070" ></i>
                                    <span style="font-size:10px;color:#707070" @click="deleteAddress(info)">删除</span>
                                </el-col>
                            </el-row>
                        </el-main>
                    </el-container>
                     <div class="addressLine"></div>
                </div>
            </el-scrollbar>
        </el-main>
        <el-footer id="shouHuoBottomPosition">
            <el-row type="flex" justify="center" style="position:fixed;bottom:10px;width:100%">
                <el-col class="imgCol">
                    <button class="btnAddress"  @click="goToAddAddress" >添加新地址</button>
                </el-col>
            </el-row>

        </el-footer>
    </el-container>
</div>
</template>
<script>
import backIcon from '../../assets/img/mine/geRenZhongXin/back.png'
import { Toast } from 'vant';
export default {
    data(){
        return{

            btnManage:'管理',
            editShow:false,
            backIcon:backIcon,
            normalHeight:document.documentElement.clientHeight,
            emptyInfo:{
                    id:'',
                    name:'',
                    phone:'',
                    sheng:'',
                    shi:'',
                    qu:'',
                    detailAddress:''
            },
            /**
             * {
            "id": 1,
            "name": "测试人员2",
            "phone": "187xxxxxxxx2",
            "province": "江苏2",
            "city": "南京2",
            "area": "南极2",
            "address": "同福客栈180号2",
            "username": "root"
        },
             */
            infos:[],
        }
    },
    mounted(){
        var normalHeight=sessionStorage.getItem('normalHeight');
        var bg = document.getElementById("background");
       // normalHeight=document.documentElement.clientHeight;
        console.log("height:"+normalHeight);
        bg.style.height = normalHeight+"px";
        bg.style.backgroundColor = "#f5f4f9"
        bg.style.margin = "0px";

        var head=document.getElementById("addressHeadPosition");
        var headHeight=normalHeight/30 *4 ;
        console.log("headHeight:"+headHeight);
        head.style.height=headHeight+"px";

        var main=document.getElementById("addressScroll");
        var mainHeight=normalHeight/30 *22;
        console.log("mainHeight:"+mainHeight);
        main.style.height=mainHeight+"px";

        // var bottom=document.getElementById("shouHuoBottomPosition");
        // var botHeight=normalHeight/30 *4;
        // console.log("btnHeight:"+botHeight);
        // bottom.style.height=botHeight+'px';

        this.getAllAddress();
    },
    methods:{
        back(){
            console.log("back:");
            this.$router.go(-1);
        },
        manageAddress(){
            if(this.btnManage=='管理'){
                this.btnManage='取消';
                this.editShow=true;
            }else{
                this.btnManage='管理';
                this.editShow=false;
            }
        },
        goToEditAddress(info){
            console.log(info);
            this.$router.push({
                path:'/editAddress',
                query:{
                    id:info.id,
                }
            })
        },
        goToAddAddress(){
            this.$router.push({
                path:'/addAddress',
            })
        },
        //获取个人所有地址
        getAllAddress(){
            var URL=this.IP.IP+'/receiptPlace/allReceiptPlace';
            console.log(URL);
            this.$ajax({
                method:'get',
                url:URL,
            }).then(response=>{
                console.log(response.data);
                var code=response.data.code;
                if(code==0){
                    this.infos=response.data.data;
                }else{
                    //Toast(response.data.msg);\
                    this.infos=[];
                }
            }).catch(error=>{
                console.log(error);
                //Toast(error);
            })
        },
        //根据id删除地址
        deleteAddress(info){
            var URL=this.IP.IP+'/receiptPlace/theReceiptPlaceSwapper';
            console.log(URL);
            this.$ajax({
                method:'delete',
                url:URL,
                data:[info.id]
            }).then(response=>{
                console.log("删除地址:",response.data);
                var code=response.data.code;
                if(code==0){
                    Toast(response.data.data);
                    this.getAllAddress();
                }else{
                    Toast(response.data.msg);
                }
            }).catch(error=>{
                console.log(error);
                //Toast(error);
            })
        }
    }
}
</script>
<style>
.boxColor{
    background-color: #fff;
}
.el-main,.el-header,.el-footer,.el-asider{
    padding: 0px ;
}
#addressHeadPosition{
    background-color: #53cdf5;
}
.addressWords{
    color: #707070;
}
.addressLine{
    width: 100%;
    height: 8px;
    /* background-color: #E0E0E0; */
    background-color: #f5f4f9;
}
.editLine{
    width: 95%;
    height: 1px;
    background-color: #f5f4f9;
}
.imgCol{
    display:flex;
    align-items:center;
    justify-content:center
}
.btnAddress{
    font-size: 1.125em;
    width: 80%;
    height: 40px;
    width: 80%;
    background-color: #53cdf5;
    border-style: none;
    outline: none;
    -webkit-border-radius: 25px;
    -moz-border-radius: 25px;
    -ms-border-radius: 25px;
    -o-border-radius: 25px;
    border-radius: 25px;
    color: #ffffff;
}
.backSize{
    height: 26px;
}
.btnAddressEdit{
    line-height: 1em;
    width: 80%;
    background-color: #fff;
      border: #53cdf5 1px solid;
    outline: none;
    -webkit-border-radius: 5px;
    -moz-border-radius: 5px;
    -ms-border-radius: 5px;
    -o-border-radius: 5px;
    border-radius: 5px;
    font-size: 1em;
    color: #53cdf5;
}
.titleSize{
    font-size:1.125em;
    color:#ffffff
}
/**
.el-checkbox__input.is-checked .el-checkbox__inner, .el-checkbox__input.is-indeterminate .el-checkbox__inner {
    background-color: #53cdf5;
    border-color: #53cdf5;
}

.el-checkbox__inner {
    border-radius: 50%;
    width: 12px;
    height: 12px;

}
.el-checkbox__input.is-checked+.el-checkbox__label {
    color: #53cdf5;
}*/
@media screen and (max-height: 600px){
  .backSize{
      height: 22px;
  }
  .titleSize{
      font-size: 1em;
  }
}
</style>
